<!-- 基于 ruoyi-vue3 的 Pagination 重构，核心是简化无用的属性，并使用 ts 重写 -->
<template>
  <Dialog :title="dialogTitle" v-model="dialogVisible" width="60%">
    <div class="titleBox">
      <div class="title">{{ detailData.title }}</div>
      <div class="info">
        <div class="text">日期：{{ formatDate(detailData.createTime) }}</div>
        <div class="text">来源：{{ detailData.projectName }}</div>
        <div class="text">作者：{{ detailData.userName }}</div>
      </div>
    </div>
    <div class="contentBox" v-html="detailData.content"></div>
    <div class="fileBox" v-if="detailData.file != undefined && detailData.file.length != 0">
      文件：
      <div class="item" v-for="(file, index) in detailData.file" :key="index">
        <el-link style="margin-left: 40px;margin-bottom: 5px;" type="primary" :icon="Download" :href="file.url" target="_blank">{{file.name}}</el-link>
      </div>
    </div>
  </Dialog>
</template>
<script lang="ts" setup>
import { formatDate } from '@/utils/formatTime'
import * as NoticeApi from '@/api/system/notice'
import { ManagementRulesApi } from '@/api/rep/managementrules'
import { NoticeDocumentApi } from '@/api/rep/noticedocument'
import { Download } from '@element-plus/icons-vue'

defineOptions({ name: 'NoticeDetail' })
const dialogVisible = ref(false) // 弹窗的是否展示
const dialogTitle = ref('详情') // 弹窗的标题

const detailData = ref<any>({})

// 打开弹窗
const open = async (type: string, id: number) => {
  dialogVisible.value = true
  //通知公告
  if (type === 'notice') {
    detailData.value = await NoticeApi.getNotice(id)
  }
  //通知文件
  else if (type === 'notice_document') {
    detailData.value = await NoticeDocumentApi.getNoticeDocument(id)
  }
  //管理办法
  else if (type === 'management_rules') {
    detailData.value = await ManagementRulesApi.getManagementRules(id)
  }
  // console.log(detailData.value)
}

// 提供 open 方法，用于打开弹窗
defineExpose({ open })
</script>
<style lang="scss" scoped>
.titleBox {
  border-bottom: 1px solid #dcdfe6;
  .title {
    font-size: 18px;
    font-weight: bold;
    text-align: center;
    margin-bottom: 20px;
  }
  .info {
    display: flex;
    align-items: center;
    justify-content: space-around;
    font-size: 14px;
    margin-bottom: 20px;
  }
}
.contentBox {
  padding: 20px 0px;
}
.fileBox {
  .item {
    display: flex;
    align-items: center;
  }
}
</style>
